import os
import time

os.chdir('C:\\&WORK\\util\\static-code-analysis-visual-metrics\\python\\')

import analyzetext


path = 'C:\\&WORK\\trunks\\Linky\\Project\\External\\STM32F10x_StdPeriph_Lib'

if os.path.isdir(path):
    ccppAnalyzer = analyzetext.CCppAnalyzer()

    timeStart = time.time()
    
    for root, dirs, files in os.walk(path):
        for name in files:
            if name.endswith(('.h', '.c', '.cpp')):
                s = os.path.join(root, name)
                print(s)
                f = open(s, 'r')
                text = f.read()
                f.close()
                ccppAnalyzer.setText(text)
                ccppAnalyzer.resetParseState()
                ccppAnalyzer.parse()
    
    timeEnd = time.time()
    print('Analyze time = ' + format(timeEnd - timeStart, '.2f') + ' seconds')
                
    ccppAnalyzer.printInfo()
else:
    print('Invalid directory path: ' + path)